/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var fieldLabel1 = new Array('本日');
var fieldLabel2 = new Array('本月');

var fieldLabel = new Array("综合电压合格率", "A类", "B类","C类", "D类", "D类城市居民端", "D类直供农村居民端");
var fieldName = new Array("rateTotal","rateA","rateB","rateC","rateD","rateDC", "rateDN");

var pointChangefieldLabel = new Array("名称", "个数" );
var pointChangefieldName = new Array("name", "quantity" );


var now = new Date();
var nowday = now.format('d');
var nowmonth = now.format('m');
var nowyear = now.format('Y');
var beginDate = now.format('Y');
var endDate = now.add(Date.YEAR, -1).format('Y');


var dateTo = {
    xtype: 'datefield',
    id: 'DateTo',
    format: 'Y年m月d日',
    width: 150,
    value: now.add(Date.DAY, -1),
    listeners: {
        select: function(c, date) {
            centergridstore.baseParams.dateTo = c.getValue().format('Ymd');
        }
    }
};

var centergridstore = new Ext.data.JsonStore({
    url: "../../servlet/data/RsjLoad",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName,
    autoLoad: true,
    baseParams: {lock: lock, cmd: "rsjOrg", dateTo: now.add(Date.DAY, -1).format('Ymd'), start: 0, limit: 99}

});
var centergridcolModel = new Ext.grid.ColumnModel({
    columns: [
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateTotal",
            align: 'center'
        },
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateA",
            align: 'center'
        },
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateB",
            align: 'center'
        },
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateC",
            align: 'center'
        },
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateD",
            align: 'center'
        },
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateDC",
            align: 'center'
        },
        {
            header: fieldLabel1[0],
            width: 100,
            dataIndex: "rateDN",
            align: 'center'
        }
    ],
    defaultSortable: true,
    rows: [
        [
            {
                width: 100,
                header: fieldLabel[0],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[1],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[2],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[3],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[4],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[5],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[6],
                colspan: 1,
                align: 'center',
                rowspan: 1
            }
        ]

    ]
});

var centergrid = new Ext.grid.GridPanel({
    title: '日合格率展示',
    store: centergridstore,
    colModel: centergridcolModel,
    enableColumnMove: false,
    height: 400,
    width: '50%',
    region: 'center',
    frame: true,
    plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
    loadMask: true,
    tbar: new Ext.Toolbar([
        {
            text: "选择日期：",
            xtype: 'label',
            style: {
                marginLeft: '20px'
            }
        },
        dateTo,
        '->',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                centergridstore.reload();
            }
        }
    ])
});

var eastgridstore = new Ext.data.JsonStore({
    url: "../../servlet/data/YsjLoad",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName,
    autoLoad: true,
    baseParams: {lock: lock, cmd: "ysjOrg", yearTo: now.format('Y'),monthTo:now.format('m'), start: 0, limit: 99}
});
eastgridstore.on("beforeLoad",function(o,options){
    o.baseParams.yearTo = Ext.getCmp("YearToCombo").getValue();
    o.baseParams.monthTo=Ext.getCmp("MonthToCombo").getValue();
});

var eastgridcolModel = new Ext.grid.ColumnModel({
    columns: [
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateTotal",
            align: 'center'
        },
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateA",
            align: 'center'
        },
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateB",
            align: 'center'
        },
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateC",
            align: 'center'
        },
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateD",
            align: 'center'
        },
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateDC",
            align: 'center'
        },
        {
            header: fieldLabel2[0],
            width: 100,
            dataIndex: "rateDN",
            align: 'center'
        }
    ],
    defaultSortable: true,
    rows: [
        [
            {
                width: 100,
                header: fieldLabel[0],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[1],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[2],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[3],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[4],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[5],
                colspan: 1,
                align: 'center',
                rowspan: 1
            },
            {
                width: 100,
                header: fieldLabel[6],
                colspan: 1,
                align: 'center',
                rowspan: 1
            }
        ]

    ]
});

var eastgrid = new Ext.grid.GridPanel({
    title: '月合格率展示',
    store: eastgridstore,
    colModel: eastgridcolModel,
    enableColumnMove: false,
    height: 400,
    width: '50%',
    region: 'east',
    frame: true,
    plugins: [new Ext.ux.plugins.GroupHeaderGrid()],
    loadMask: true,
    tbar: new Ext.Toolbar([
        {
            text: "选择日期：",
            xtype: 'label',
            style: {
                marginLeft: '20px'
            }
        },
        yearToCombo,
        lblYear,
        monthToCombo,
        lblMonth,
        '->',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                eastgridstore.reload();
            }
        }
    ])
});


var westpanelstore = new Ext.data.JsonStore({    
    url: "../../servlet/system/PointLoad",
    root: 'data',
    idProperty: 'statusTo',
    totalProperty: 'count',
    fields: ["statusTo","quantity"],
    autoLoad: true,
    baseParams:{cmd:"changeSummary",dateFrom:now.add(Date.MONTH,-1).format("Ymd"),dateTo:now.format("Ymd"),reportStatus:-1,range:-1,start:0,limit:99}
});

var centerpanelstore = new Ext.data.JsonStore({
    
    url: "../../servlet/system/ExceptionLoad",
    root: 'data',
    idProperty: 'statusTo',
    totalProperty: 'count',
    fields: ["statusTo","quantity"],
    autoLoad: true,
    baseParams:{lock:"",cmd:"pointException",dateFrom:now.add(Date.DAY,-1).format("Ymd"),dateTo:now.add(Date.DAY,-1).format("Ymd"),reportStatus:1,range:-1,start:0,limit:99}

});

var eastpanelstore = new Ext.data.JsonStore({    
    url: "../../servlet/system/PointLoad",
    root: 'data',
    idProperty: 'name',
    totalProperty: 'count',
    fields: pointChangefieldName,
    autoLoad: true,
    baseParams:{cmd:"typeSummary",reportStatus:1,range:-1,start:0,limit:99}
});

var downgridcolModel = new Ext.grid.ColumnModel({
    columns: [
        {
            header: pointChangefieldLabel[0],
            width: 200,
            dataIndex: pointChangefieldName[0],
            align: 'center'
        },
        {
            header: pointChangefieldLabel[1],
            width: 150,
            dataIndex: pointChangefieldName[1],
            align: 'center'
        }

    ],
    defaultSortable: true
});

var westpanel = new Ext.grid.GridPanel({
    title: '测点变更',
    width: '33%',
    region: 'west',
    store: westpanelstore,
    columns: [
        {
            header: "名称",
            width: 200,
            dataIndex: "statusTo",
            align: 'center'
        },
        {
            header: "数量",
            width: 150,
            dataIndex: "quantity",
            align: 'center'
        }
    ]
});

var centerpanel = new Ext.grid.GridPanel({
    title: '测点异常',
    width: '33%',
    region: 'center',
    store: centerpanelstore,
    columns: [
        {
            header: "名称",
            width: 200,
            dataIndex: "statusTo",
            align: 'center'
        },
        {
            header: "数量",
            width: 150,
            dataIndex: "quantity",
            align: 'center'
        }
    ]
});

var eastpanel = new Ext.grid.GridPanel({
    title: '测点运维',
    width: '33%',
    region: 'east',
    store: eastpanelstore,
    columns: [
        {
            header: "名称",
            width: 200,
            dataIndex: "name",
            align: 'center'
        },
        {
            header: "数量",
            width: 150,
            dataIndex: "quantity",
            align: 'center'
        }
    ]
});

var northPanel = new Ext.Panel({
    title: currentOrgName+' 合格率展示',
    width: '100%',
    height: 300,
    layout: 'border',
    region: 'north',
    items: [
        centergrid, eastgrid
    ]
});

var centerPanel = new Ext.Panel({
    width: '100%',
    layout: 'border',
    region: 'center',
    items: [
        westpanel, centerpanel, eastpanel
    ]
});


function buildWindow() {
    var applicationUI = new Ext.Viewport({
        layout: 'border',
        items: [
            centerPanel, northPanel
        ]
    });
}
Ext.onReady(buildWindow);  